<html>
<head><meta charset="utf-8"><title>Custom clippy with cargo · clippy · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/index.html">clippy</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Custom.20clippy.20with.20cargo.html">Custom clippy with cargo</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="243818249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Custom%20clippy%20with%20cargo/near/243818249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eholk <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Custom.20clippy.20with.20cargo.html#243818249">(Jun 24 2021 at 17:20)</a>:</h4>
<p>Is there a way to tell cargo to use a version of clippy I built myself for <code>cargo clippy</code>?</p>



<a name="243827012"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Custom%20clippy%20with%20cargo/near/243827012" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Custom.20clippy.20with.20cargo.html#243827012">(Jun 24 2021 at 18:28)</a>:</h4>
<p>Run <code>cargo install --path . --force</code> in the Clippy dir. You may have to set <code>LD_LIBRARY_PATH=$(rustc +&lt;toolchain-you-compiled-clippy-with&gt; --print=sysroot)/lib</code> for Clippy to work. After that <code>cargo clippy</code> should run your self-compiled version of Clippy. You can verify that with <code>cargo clippy --version</code></p>



<a name="243827376"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Custom%20clippy%20with%20cargo/near/243827376" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Custom.20clippy.20with.20cargo.html#243827376">(Jun 24 2021 at 18:31)</a>:</h4>
<p>You may have to copy the files installed to <code>.cargo/bin/*clippy*</code> to <code>$(rustc +&lt;toolchain-you-compiled-clippy-with&gt; --print=sysroot)/bin</code>, but I'm not sure about that.</p>



<a name="243827475"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Custom%20clippy%20with%20cargo/near/243827475" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Custom.20clippy.20with.20cargo.html#243827475">(Jun 24 2021 at 18:31)</a>:</h4>
<p>^ That's how it works on Linux. Similar steps on Windows and MacOS should also work. I can't test this on those two platforms though.</p>



<a name="243854643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Custom%20clippy%20with%20cargo/near/243854643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eholk <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Custom.20clippy.20with.20cargo.html#243854643">(Jun 24 2021 at 22:30)</a>:</h4>
<p>Thanks, I'll give that a try. It looks like this overrides the released version of clippy, right? Is there a way to restore the released version afterwards?</p>



<a name="243887071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Custom%20clippy%20with%20cargo/near/243887071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Custom.20clippy.20with.20cargo.html#243887071">(Jun 25 2021 at 08:12)</a>:</h4>
<p>Yes, you can just <code>rustup component remove clippy --toolchain=...</code> and then <code>rustup component add clippy --toolchain=...</code></p>



<a name="245588708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Custom%20clippy%20with%20cargo/near/245588708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rukai <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Custom.20clippy.20with.20cargo.html#245588708">(Jul 11 2021 at 05:09)</a>:</h4>
<p>I tried following these instructions but it failed as follows:<br>
I ran <code>cargo install --path . --force</code> in the clippy repo root, which succeeded.<br>
Then I ran the following in some crate directory:</p>
<div class="codehilite"><pre><span></span><code>rukai@memes src$ export LD_LIBRARY_PATH=$(rustc +nightly-2021-07-01 --print=sysroot)/lib
rukai@memes src$ cargo clippy
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn&#39;t exit successfully: `/home/rukai/.cargo/bin/clippy-driver rustc - --crate-name ___ --print=file-names -C link-arg=-fuse-ld=lld --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=cfg` (exit status: 127)
  --- stderr
  /home/rukai/.cargo/bin/clippy-driver: error while loading shared libraries: librustc_driver-cf542089f8fca1b6.so: cannot open shared object file: No such file or directory
</code></pre></div>



<a name="245703005"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Custom%20clippy%20with%20cargo/near/245703005" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Custom.20clippy.20with.20cargo.html#245703005">(Jul 12 2021 at 15:30)</a>:</h4>
<p>Did you try to copy the clippy binaries also to the toolchain folder of the nightly you compiled Clippy with.</p>
<p>Please also check if the path produced by <code>echo "$(rustc +nightly-2021-07-01 --print=sysroot)/lib"</code> contains the file <code>librustc_driver-cf542089f8fca1b6.so</code> or another <code>librustc_driver-*.so</code> file</p>



<a name="245818407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Custom%20clippy%20with%20cargo/near/245818407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rukai <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Custom.20clippy.20with.20cargo.html#245818407">(Jul 13 2021 at 12:44)</a>:</h4>
<p>I tried copying the binaries to the toolchain folder of the 2021-07-01 nightly but it didnt help.<br>
The clippy binary run from <code>cargo clippy</code> seem to be from <code>.cargo/bin</code>.</p>
<p>And it seems like LD_LIBRARY_PATH is not working as the missing .so file is in the LD_LIBRARY_PATH dir.</p>
<div class="codehilite"><pre><span></span><code>rukai@memes canon_collision$ echo $LD_LIBRARY_PATH
/home/rukai/.rustup/toolchains/nightly-2021-07-01-x86_64-unknown-linux-gnu/lib
rukai@memes canon_collision$ ls $LD_LIBRARY_PATH
libLLVM-12-rust-1.55.0-nightly.so  librustc_driver-cf542089f8fca1b6.so  libstd-37fdd654777c296f.so  libtest-08487f8e282f19e0.so  rustlib
rukai@memes canon_collision$ cargo clippy
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn&#39;t exit successfully: `/home/rukai/.cargo/bin/clippy-driver rustc - --crate-name ___ --print=file-names -C link-arg=-fuse-ld=lld --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=cfg` (exit status: 127)
  --- stderr
  /home/rukai/.cargo/bin/clippy-driver: error while loading shared libraries: librustc_driver-cf542089f8fca1b6.so: cannot open shared object file: No such file or directory
</code></pre></div>
<p>btw, I'm only trying to do this because I want to able to run changes I make to clippy on my own projects, if there is a better way to do that without being able to run it via <code>cargo clippy</code> then that would be fine too.</p>



<a name="245827925"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Custom%20clippy%20with%20cargo/near/245827925" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Custom.20clippy.20with.20cargo.html#245827925">(Jul 13 2021 at 13:56)</a>:</h4>
<p>Ah ok. Then the easiest way is to use our <code>lintcheck</code> tool for this. The documentation for this tool is here: <a href="https://github.com/rust-lang/rust-clippy/tree/master/lintcheck#cargo-lintcheck">https://github.com/rust-lang/rust-clippy/tree/master/lintcheck#cargo-lintcheck</a></p>
<p>TL;DR:</p>
<ol>
<li>create a config file with your crates (see the above readme on how to do that)</li>
<li>run <code>cargo lintcheck --crates-toml /path/to/config-file.toml</code></li>
</ol>



<a name="245870579"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Custom%20clippy%20with%20cargo/near/245870579" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Custom.20clippy.20with.20cargo.html#245870579">(Jul 13 2021 at 18:54)</a>:</h4>
<p>See <a href="https://github.com/rust-lang/rust-clippy/pull/7460">https://github.com/rust-lang/rust-clippy/pull/7460</a>. I may have some new guidance on this.</p>



<a name="245934254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Custom%20clippy%20with%20cargo/near/245934254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rukai <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Custom.20clippy.20with.20cargo.html#245934254">(Jul 14 2021 at 08:54)</a>:</h4>
<p>I was trying to use lintcheck earlier but was getting "lintcheck needs to be run from clippys repo root!" even though I was in the clippy repo root.<br>
But I tried lintcheck just now and its working! No idea if there was a fix merged or maybe it was all the fiddling with toolchains from earlier.</p>
<p>But now for some reason when I run it on my local project i'm getting:</p>
<div class="codehilite"><pre><span></span><code>    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
     Running `lintcheck/target/debug/lintcheck --crates-toml lintcheck/embassy.toml`
Compiling clippy...
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Done compiling
Not copying /home/rukai2/Projects/Crates/embassy/embassy to target/lintcheck/sources/embassy, destination already exists
1/1 100% Linting embassy local

WARNING: bad exit status after checking embassy local

Writing logs to lintcheck-logs/embassy_logs.txt

Stats:
</code></pre></div>
<p>But other projects seem to be working so I'll investigate on my end for a while.<br>
Thanks for the help!</p>



<a name="245966074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Custom%20clippy%20with%20cargo/near/245966074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Custom.20clippy.20with.20cargo.html#245966074">(Jul 14 2021 at 14:18)</a>:</h4>
<p>Have you modified anything in Clippy before running the tool? This usually means, that Clippy ICEd when running on the embassy crate.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>